package com.krautzlabs;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class DrawThread extends Thread{
    private SurfaceHolder _surfaceHolder;
    private MapView _mapView;
    private boolean _run = false;
    
    public DrawThread(SurfaceHolder surfaceHolder, MapView drawableView)
    {
            this._surfaceHolder = surfaceHolder;
            this._mapView = drawableView;
    }
    
    public void setRunning(boolean run)
    {
            this._run = run;
    }
    
    
    public SurfaceHolder getSurfaceHolder()
    {
            return this._surfaceHolder;
    }
    
    public void run()
    {
        Canvas c;
        while(_run)
        {
            c = null;
            try{
                c = this._surfaceHolder.lockCanvas(null);
                synchronized(_surfaceHolder)
                {
                        this._mapView.onDraw(c);
                }
            } finally
            {
                if(c != null)
                {
                        this._surfaceHolder.unlockCanvasAndPost(c);
                }
            }                   
        }
            
    }
}